﻿#region

using System.Windows.Forms;

#endregion

namespace GGEditor.API.Utility.Forms
{
    /// <summary>
    /// A list view that ignores the erase background message from Windows,
    /// thus preventing an annoying update flicker.
    /// </summary>
    public class FlickerlessListView : ListView
    {
        // http://stackoverflow.com/questions/442817/c-flickering-listview-on-update
        public FlickerlessListView()
        {
            SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint, true);
            SetStyle(ControlStyles.EnableNotifyMessage, true);
        }

        protected override void OnNotifyMessage(Message m)
        {
            //Filter out the WM_ERASEBKGND message
            if (m.Msg != 0x14)
                base.OnNotifyMessage(m);
        }
    }
}